<?php
defined('BASEPATH') OR exit('No direct script access allowed');

//动作
class Sport extends MY_Controller {

	function __construct(){
		parent::__construct();
		
	}	
	
	//start
	/**
	* @name 获取栏目列表
	* @return 
	*/
	//end
	function get_cate_list(){
		
		$this->load->model('Sport/SportCatModel','SportCat');
		$list = $this->SportCat->get_list();
		
		$this->data_out($list);
	}
	
	//start
	/**
	* @name 获取栏目详细
	* @param id true char 栏目ID
	* @return 
	*/
	//end
	function get_cate_info(){
		$id = $this->input->post('id',NULL,0);
		
		
		$this->load->model('Sport/SportCatModel','SportCat');
		
		
		$info = $this->SportCat->_id_get_info($id);
		if(!$info){
			$this->err_out('数据不存在');
		}

		
		$this->data_out($info);
	}
	//start
	/**
	* @name 栏目ID获取动作列表
	* @param id true char 栏目ID
	* @return 
	*/
	//end
	function cat_get_list(){
		$id = $this->input->post('id',NULL,0);
		
		$this->load->model('Sport/SportCatModel','SportCat');
		$this->load->model('Sport/SportModel','Sport');
		
		$info = $this->SportCat->_id_get_info($id);
		if(!$info){
			$this->err_out('数据不存在');
		}
		
		$list = $this->Sport->get_list($id);

		$this->data_out($list);
	}
	
	//start
	/**
	* @name 添加动作栏目
	* @param name true char 名称
	* @return 
	*/
	//end
	function add_cate(){

		$arr = array(
			'name'=>$this->input->post('name',NULL,'')
		);
		
		$ver_arr = array(
			'name'=>"名称不能为空",
		);
		
		$result = $this->CheckData($ver_arr,$arr);
		if($result){
			$this->err_out($result);
		}
		
		$this->load->model('Sport/SportCatModel','SportCat');
		
		$info = $this->SportCat->name_is_exits($arr['name']);
		if($info){
			$this->err_out('名称已经存在');
		}
		
		$id = $this->SportCat->add($arr);
		$arr['id'] = $id;
		
		
		$this->data_out($arr);
	}
	//start
	/**
	* @name 添加动作
	* @param name true char 名称
	* @param cat_id true int 栏目ID
	* @param theme_img true char 图片
	* @param content true char 详情
	* @param rest false char 休息时间（秒）
	* @param duration false char 时长（秒）
	* @param frequency false char 运动次数（次）
	* @param group false char 组
	* @param type true ini 是否添加到库，0.不添加，1.添加
	* @return 
	*/
	//end
	function add(){
		$user_id = $this->user_id;
		$time = time();
		
		$arr = array(
			'name' => $this->input->post('name',NULL,''),
			'cat_id' => $this->input->post('cat_id',NULL,0),
			'theme_img' => $this->input->post('theme_img',NULL,''),
			'content' => $this->input->post('content',NULL,''),
			'rest' => $this->input->post('rest',NULL,''),
			'duration' => $this->input->post('duration',NULL,''),
			'frequency' => $this->input->post('frequency',NULL,''),
			'group' => $this->input->post('group',NULL,''),
			'type' => $this->input->post('type',NULL,0),
			'cid'=>$user_id,
			'addtime'=>$time
		);
		
		
		$ver_arr = array(
			'name'=>"动作名称不能为空",
			'cat_id'=>"请选择一个栏目",
			'theme_img'=>"主题封面不能为空",
			'content'=>"详细介绍不能为空",
		);
		
		$result = $this->CheckData($ver_arr,$arr);
		if($result){
			$this->err_out($result);
		}
		
		
		$this->load->model('Sport/SportCatModel','SportCat');
		$this->load->model('Sport/SportModel','Sport');
		
		$info = $this->SportCat->_id_get_info($arr['cat_id']);
		if(!$info){
			$this->err_out('栏目不存在');
		}
		
		$inser_id = $this->Sport->add($arr);
		$arr['id'] = $inser_id;
		
		$this->data_out($arr);
	}
}
